package cn.initcap.algorithm.lambda;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * Comparator的使用
 *
 * @author initcap
 * @date Created in 2018/11/20 AM9:13.
 */
public class ComparatorUseLambda {

    public static void main(String[] args) {
        List<Empoy> empoyList = new ArrayList<>();
        Date date = new Date();
        date.setTime(1333333333333L);
        empoyList.add(new Empoy("initcap", 12, date));
        Date date1 = new Date();
        date1.setTime(1444444444444L);
        empoyList.add(new Empoy("lixiaolong", 24, date1));
        Date date2 = new Date();
        date2.setTime(1555555555555L);
        empoyList.add(new Empoy("liangliang", 12, date2));
        empoyList.sort(Comparator.comparing(Empoy::getAge).thenComparing(Empoy::getBirthday).reversed());
        empoyList.forEach(empoy -> System.out.println(empoy));
    }

    static class Empoy {

        private String name;
        private int age;
        private Date birthday;

        public Empoy(String name, int age, Date birthday) {
            this.name = name;
            this.age = age;
            this.birthday = birthday;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public Date getBirthday() {
            return birthday;
        }

        public void setBirthday(Date birthday) {
            this.birthday = birthday;
        }

        @Override
        public String toString() {
            return "Empoy{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    ", birthday=" + birthday +
                    '}';
        }
    }
}
